package com.mlizhi.modules.spec.detect;

import android.animation.Animator;
import android.animation.Animator.AnimatorListener;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.Response.Listener;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.mlizhi.base.MlzApplication;
import com.mlizhi.base.NetWorkManager;
import com.mlizhi.base.SecurityUtil;
import com.mlizhi.base.Session;
import com.mlizhi.kingdom.R;
import com.mlizhi.modules.spec.IRegInterface;
import com.mlizhi.modules.spec.ISpecInterface;
import com.mlizhi.modules.spec.dao.DaoSession;
import com.mlizhi.modules.spec.dao.DetectDao;
import com.mlizhi.modules.spec.dao.model.DetectModel;
import com.mlizhi.modules.spec.detect.ble.BluetoothLeService;
import com.mlizhi.modules.spec.util.JsonUtil;
import com.mlizhi.utils.Constants;
import com.mlizhi.widgets.wave.CircularView;
import com.umeng.analytics.MobclickAgent;

import org.json.JSONArray;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
@SuppressLint("NewApi")
public class SpecDetectFragment extends Fragment{
	// 缓存Fragment view
	private View rootView;
	// ISpecInterface的实例，用来使SpecActivity做回调的
	private ISpecInterface specCallback;

	private Activity mContext;
	private CircularView circularView;
	private ObjectAnimator objAnimator;
	private TextView detectStatus, detectResultValue;
	private RelativeLayout popResult;
	private TextView popCompareLastedDetect;
	private Session mSession = null;
	private Animation animation2in,animation2out;
	// 搜索设备……
	private static final int BLE_FLAG_SEARCH_START = 0x1000;
	// 停止搜索……
	private static final int BLE_FLAG_SEARCH_STOP = 0x1001;
	// 断开状态
	private static final int BLE_FLAG_DISCONNECT = 0x1002;
	// 连接已经成功
	private static final int BLE_FLAG_CONNECTED = 0x1003;
	// 发现服务
	private static final int BLE_FLAG_DISCOVER_SERVICE = 0x1004;
	// 测试中……
	private static final int BLE_FLAG_DATA_AVAILABLE = 0x1005;
	// 检测时间不足5s
	public static final int BLE_DETECT_FAILED_TIMELESS = 0x1006;
	// 值太小(不足20)
	public static final int BLE_DETECT_FAILED_VALUE_LOW = 0x1007;
	// 正常的水分值(接收时)
	public static final int BLE_DETECT_WATER_VALUE = 0x1008;
	// 开始检测
	public static final int BLE_FLAG_START_DETECT = 0x1011;

	private MlzApplication mlzApplication = null;

	private static SpecDetectFragment specDetectFragment;
	
	//部位选择
	private RadioGroup partTypeGroup;
	//检测前后的开关
	private CheckBox nurserTypeCheckBox;
	
	private TextView nurserTypeSwitchLabel;

	//检测部位变量
	private int tempPartType = Constants.BODY_PART_HAND;
	private String partType = "2";
	//护理前后变量
	private int tempNurserType = Constants.NURSER_TYPE_PRE;
	private String nurserTypeValue = "";
	
	private DaoSession daoSession;
    private DetectDao detectDao;
    private RequestQueue mRequestQueue;
    private IRegInterface regInterface;
    private float lastedDetectValue = 0f;

//  //用来保存不同部位用不同产品测试的值
//    private List<HashMap<String,String>> tempValueMapList = new ArrayList<HashMap<String,String>>();
//    private HashMap<String,String> tempValueMap = new HashMap<String,String>();

	public SpecDetectFragment() {

	}

	public static SpecDetectFragment getNewInstance() {
		if (specDetectFragment == null) {
			specDetectFragment = new SpecDetectFragment();
		}
		return specDetectFragment;
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		this.mContext = activity;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.mContext = getActivity();
		this.mSession = Session.get(getActivity().getApplicationContext());
		mlzApplication = (MlzApplication) getActivity().getApplication();
		daoSession = mlzApplication.getDaoSession();
		detectDao = daoSession.getDetectDao();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		if (rootView == null) {
			rootView = inflater.inflate(R.layout.fragment_spec_detect,container, false);
		}
		// 缓存的rootView需要判断是否已经被加过parent，
		// 如果有parent需要从parent删除，要不然会发生这个rootview已经有parent的错误。
		ViewGroup parent = (ViewGroup) rootView.getParent();
		if (parent != null) {
			parent.removeView(rootView);
		}
		circularView = (CircularView) rootView.findViewById(R.id.id_water_circular_view);
		circularView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
		detectStatus = (TextView) rootView.findViewById(R.id.id_detect_status);
		detectResultValue = (TextView) rootView.findViewById(R.id.id_detect_result_value);
		popResult = (RelativeLayout) rootView.findViewById(R.id.pop_result);
		popCompareLastedDetect = (TextView) rootView.findViewById(R.id.id_compare_lasted_detect);
		popCompareLastedDetect.setText(getString(R.string.compare_lasted_detect,0.00f));
		partTypeGroup = (RadioGroup) rootView.findViewById(R.id.id_detect_pos_group);
		nurserTypeCheckBox= (CheckBox) rootView.findViewById(R.id.id_nurser_status);
		nurserTypeSwitchLabel = (TextView) rootView.findViewById(R.id.id_nurser_status_label);
		
		ViewTreeObserver vto2 = circularView.getViewTreeObserver();
		vto2.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
			@Override
			public void onGlobalLayout() {
				circularView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
				circularView.startWave();
			}
		});
		return rootView;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		specCallback = (ISpecInterface) getActivity();
		regInterface  = (IRegInterface) getActivity();
//		mContext.registerReceiver(mGattUpdateReceiver,makeGattUpdateIntentFilter());
//		mContext.startService(new Intent(mContext, BleService.class));
		animation2in = (Animation) AnimationUtils.loadAnimation(mContext,R.anim.in_from_down);
		animation2in.setDuration(1*1000);
		animation2out = (Animation) AnimationUtils.loadAnimation(mContext,R.anim.out_to_down);
		animation2out.setDuration(1*1000);
		rootView.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(popResult != null) {
					popResult.setVisibility(View.GONE);
				}	
			}
		});
		String supportBle = mlzApplication.getGlobalVariable("supportBle");
		if(supportBle != null && !"".equals(supportBle)){
			circularView.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
//					mContext.startService(new Intent(mContext, BleService.class));
					regInterface.reScan4Device();
				}
			});
			
		}
		popResult.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				popResult.startAnimation(animation2out);
				popResult.setVisibility(View.GONE);
				Intent intent = new Intent(mContext,SpecDetectResultActivity.class);
				float water = (int) (waterValue / 10f) * 0.1f;
				intent.putExtra("current_water_value", water);
				intent.putExtra("nurser_type", tempNurserType);
				mContext.startActivity(intent);
			}
		});
		
//		tempValueMap.put("type", "2");
		//缓存到本次结果页面显示 
		mlzApplication.putGlobalVariable("current_part_type", String.valueOf(tempPartType));
		
		partTypeGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				switch (checkedId) {
					case R.id.id_detect_pos_face:
						tempPartType = Constants.BODY_PART_FACE;
						MobclickAgent.onEvent(mContext,"BODY_PART_FACE");
//					tempValueMap.put("type", "1");
						partType = "1";
						break;
					case R.id.id_detect_pos_eye:
						tempPartType = Constants.BODY_PART_EYE;
						MobclickAgent.onEvent(mContext,"BODY_PART_EYE");
//					tempValueMap.put("type", "3");
						partType = "3";
						break;
					case R.id.id_detect_pos_hand:
						tempPartType = Constants.BODY_PART_HAND;
						MobclickAgent.onEvent(mContext,"BODY_PART_HAND");
//					tempValueMap.put("type", "2");
						partType = "2";
						break;
					case R.id.id_detect_pos_neck:
						tempPartType = Constants.BODY_PART_NECK;
						MobclickAgent.onEvent(mContext,"BODY_PART_NECK");
//					tempValueMap.put("type", "5");
						partType = "5";
						break;

				default:tempPartType = Constants.BODY_PART_HAND;
					break;
				}
				mlzApplication.putGlobalVariable("current_part_type", String.valueOf(tempPartType));
			}
		});
		mlzApplication.putGlobalVariable("current_nurser_status", String.valueOf(tempNurserType));
		nurserTypeCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				 if (!isChecked) {  
					 	tempNurserType = Constants.NURSER_TYPE_PRE;
					 	MobclickAgent.onEvent(mContext,"NURSER_TYPE_PRE");
					 	nurserTypeSwitchLabel.setText(R.string.nurser_status_pre);
					 	circularView.setProgress(0.0f);
					 	detectResultValue.setText("0.0%");
	                } else {  
	                	tempNurserType = Constants.NURSER_TYPE_POST;
	                	MobclickAgent.onEvent(mContext,"NURSER_TYPE_POST");
	                	nurserTypeSwitchLabel.setText(R.string.nurser_status_post);
	                	circularView.setProgress(0.0f);
	                	detectResultValue.setText("0.0%");
	                }  
				 if(popResult != null) {
						popResult.setVisibility(View.GONE);
					}	
				 mlzApplication.putGlobalVariable("current_nurser_status", String.valueOf(tempNurserType));
			}
		});
	}

	
	
	@Override
	public void onStart() {
		super.onStart();
	}

	@Override
	public void onResume() {
		super.onResume();
		if(popResult != null) {
			popResult.setVisibility(View.GONE);
		}	
	}

	@Override
	public void onPause() {
		super.onPause();
	}

	@Override
	public void onStop() {
		super.onStop();
	}

	@Override
	public void onDestroyView() {
		super.onDestroyView();
//		mContext.unregisterReceiver(mGattUpdateReceiver);
//		mContext.stopService(new Intent(mContext, BleService.class));
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

	@Override
	public void onDetach() {
		super.onDetach();
	}

	
	
	
	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
//		mContext.startService(new Intent(mContext, BleService.class));
		if(resultCode == Activity.RESULT_CANCELED){
			detectStatus.setText(R.string.ble_detect_step_unstartble);
		}else if(resultCode == Activity.RESULT_OK){
			regInterface.reScan4Device();
		}
	}

	/**
	 *
	 * @param circularView
	 * @param listener
	 */
	private void animate(final CircularView circularView, final AnimatorListener listener) {
		final float progress = 1.00f;
		int duration = 6000;
		circularView.setProgress(0.0f);
		animate(circularView, listener, progress, duration);
	}

	
	private void animate(final CircularView circularView,final AnimatorListener listener, final float progress,final int duration) {
		if (objAnimator == null) {
			objAnimator = ObjectAnimator.ofFloat(circularView, "progress", progress);
		}
		objAnimator.setDuration(duration);

		objAnimator.addListener(new AnimatorListener() {

			@Override
			public void onAnimationCancel(final Animator animation) {
				circularView.setProgress(0.0f);
				// objAnimator.cancel();
			}

			@Override
			public void onAnimationEnd(final Animator animation) {
				circularView.setProgress(1.0f);
				// objAnimator.end();
			}

			@Override
			public void onAnimationRepeat(final Animator animation) {
			}

			@Override
			public void onAnimationStart(final Animator animation) {
				circularView.setProgress(0.0f);
			}
		});
		if (listener != null) {
			objAnimator.addListener(listener);
		}

		objAnimator.addUpdateListener(new AnimatorUpdateListener() {

			float count = 0.0f;

			@Override
			public void onAnimationUpdate(final ValueAnimator animation) {
				// count = 0.012f;
				// circularView.setProgress(count);
			}
		});
		objAnimator.start();

	}

	int waterValue = 0;
	double receivedWaterData = 0.0d;
	float tempWaterValue = 0f;
	// 将测水设备测试的状态和结果展现到UI上
	private Handler mHandler = new Handler(new android.os.Handler.Callback() {
		@Override
		public boolean handleMessage(Message msg) {
			if(!isAdded()){
				return false;
			}
			int what = msg.what;
			switch (what) {
			case BLE_FLAG_SEARCH_START:
				detectStatus.setText(R.string.device_status_start_scan);
				circularView.setClickable(false);
				//Log.e("======", "===正在搜索==");
				break;
			case BLE_FLAG_SEARCH_STOP:
				circularView.setClickable(true);
				detectStatus.setText(R.string.device_status_stop_scan);
				//Log.e("======", "===搜索停止==");
				break;
			case BLE_FLAG_DISCONNECT:
				detectStatus.setText(R.string.device_status_not_connected);
				circularView.setClickable(true);

//				mlzApplication.putGlobalVariable("connected", "");
				//Log.e("======", "===断开连接==");
				break;
			case BLE_FLAG_CONNECTED:
				detectStatus.setText(R.string.device_status_only_connected);
				//Log.e("======", "===连接上==");
//				mlzApplication.putGlobalVariable("connected", "connected");
				break;
			case BLE_FLAG_DISCOVER_SERVICE:
				detectStatus.setText(R.string.device_status_connecting);
				//Log.e("======", "===已经连接==");
				break;
			case BLE_FLAG_START_DETECT:
				detectStatus.setText("开始检测");
				//Log.e("======", "===开始检测===" + waterValue);
				if (circularView != null) {
					animate(circularView, null);
				}
				// detectPost(receivedWaterData);
				break;
			case BLE_FLAG_DATA_AVAILABLE:
				detectStatus.setText(R.string.device_status_detecting);
				// //Log.e("111111111111111", "======="+tempWaterValue);
				detectResultValue.setText(String.valueOf(Math
						.ceil(tempWaterValue * 10) / 10f + "%"));
				//Log.e("======", "===正在检测===");
				break;
			case BLE_DETECT_FAILED_TIMELESS:

				detectStatus
						.setText(R.string.device_status_detecting_less_time);
				//Log.e("======", "===检测值过低===");
				detectResultValue.setText("0.0%");
				break;
			case BLE_DETECT_FAILED_VALUE_LOW:
				detectStatus
						.setText(R.string.device_status_detecting_low_value);
				//Log.e("======", "===检测时间过短===");
				detectResultValue.setText("0.0%");
				break;
			case BLE_DETECT_WATER_VALUE:
				waterValue = (Integer) msg.obj;
				// detectStatus.setText(mActivity.getString(R.string.device_status_water_value)
				// + waterValue * 0.001f);
				float water = (int) (waterValue / 10f) * 0.1f;
				detectStatus.setText(mContext
						.getString(R.string.device_status_success_water_value));
				detectResultValue.setText("" + water + "%");
				if(lastedDetectValue == 0) {
					lastedDetectValue = water;
					popCompareLastedDetect.setText("");
				}else {
					if(isAdded()){
						float compareValue = (water - lastedDetectValue)/lastedDetectValue * 100f;
						if(compareValue > 0 ){
							popCompareLastedDetect.setTextColor(Color.RED);
							popCompareLastedDetect.setText(getString(R.string.compare_lasted_detect,compareValue));
						}
						else{
							Toast.makeText(mContext,"请护理后重新检测！",Toast.LENGTH_SHORT).show();
							popCompareLastedDetect.setText("");
						}
					}
				}
				popResult.setVisibility(View.VISIBLE);
				popResult.startAnimation(animation2in);
//				if(tempNurserType == Constants.NURSER_TYPE_PRE){
//					tempValueMap.put("beforeValue", String.valueOf(water));
//				}else if(tempNurserType == Constants.NURSER_TYPE_POST){
//					tempValueMap.put("afterValue", String.valueOf(water));
//				}
				nurserTypeValue = String.valueOf(water);
//				mlzApplication.putGlobalVariable("current_water_value", String.valueOf(water));
				saveDetectResult();
				//Log.e("======", "===检测值===" + waterValue);
				break;

			}
			return false;
		}
	});


	Timer animTimer = null;
//	Timer animTimer2 = null;

//	public final BroadcastReceiver mGattUpdateReceiver = new BroadcastReceiver() {
	public class BleBroadcastReceiver extends BroadcastReceiver{
		boolean received = false;
		Message msg = null;

		@SuppressLint("HandlerLeak")
		@Override
		public void onReceive(Context context, Intent intent) {
			final String action = intent.getAction();
			if (BluetoothLeService.HIDE_SCAN_BTN.equals(action)) {// 搜索设备,隐藏手动扫描按钮
				msg = mHandler.obtainMessage();
				msg.what = BLE_FLAG_SEARCH_START;
				mHandler.sendMessage(msg);
			} else if (BluetoothLeService.SHOW_SCAN_BTN.equals(action)) {// 停止搜索,显示手动扫描按钮
				msg = mHandler.obtainMessage();
				msg.what = BLE_FLAG_SEARCH_STOP;
				mHandler.sendMessage(msg);

			} else if (BluetoothLeService.ACTION_GATT_DISCONNECTED.equals(action)) {// 处于断开状态，如果蓝牙开启正收搜蓝牙设备
				msg = mHandler.obtainMessage();
				msg.what = BLE_FLAG_DISCONNECT;
				mHandler.sendMessage(msg);
				if (animTimer != null) {
					animTimer.cancel();
				}
				regInterface.mConnect(false);
			} else if (BluetoothLeService.ACTION_GATT_CONNECTED.equals(action)) {// 连接已经成功
				msg = mHandler.obtainMessage();
				msg.what = BLE_FLAG_CONNECTED;
				mHandler.sendMessage(msg);
			} else if (BluetoothLeService.ACTION_GATT_SERVICES_DISCOVERED.equals(action)) {// 发现服务
				msg = mHandler.obtainMessage();
				msg.what = BLE_FLAG_DISCOVER_SERVICE;
				mHandler.sendMessage(msg);
				regInterface.mConnect(true);
				regInterface.getBleData();
			} else if (BluetoothLeService.ACTION_DATA_AVAILABLE.equals(action)) {// 发送数据
				int data = intent.getIntExtra(BluetoothLeService.EXTRA_DATA, 0);
				// //Log.e(TAG,"== the data is ====: "+data);
				if (!received && data == 2) {// 开始测试
					received = true;
					tempWaterValue = 0.0f;

					msg = mHandler.obtainMessage();
					msg.what = BLE_FLAG_START_DETECT;
					mHandler.sendMessage(msg);
					animTimer = new Timer();
					animTimer.schedule(new TimerTask() {
						public void run() {
							msg = mHandler.obtainMessage();
							msg.what = BLE_FLAG_DATA_AVAILABLE;
							mHandler.sendMessage(msg);
							if(tempWaterValue <= 20.0f){
								tempWaterValue += 0.27f;
							}else if(tempWaterValue > 20.0f && receivedWaterData > 0.0d && tempWaterValue <= (float) receivedWaterData){
								tempWaterValue = tempWaterValue + ((float) receivedWaterData - 20.0f) / 15f;
							}else if (receivedWaterData > 0.0d && tempWaterValue >= (float) receivedWaterData) {
								if (animTimer != null) {
									animTimer.cancel();
								}
								saveDetectValue();
								msg = mHandler.obtainMessage();
								msg.what = BLE_DETECT_WATER_VALUE;
								msg.obj = (int)receivedWaterData * 100;
								mHandler.sendMessage(msg);
							}
//							//Log.e("************", ""+tempWaterValue);
						}
					}, 0, 50);

				} else if (received && data == 3) {// 测量时间太短
					msg = mHandler.obtainMessage();
					msg.what = BLE_DETECT_FAILED_TIMELESS;
					mHandler.sendMessage(msg);
					if (objAnimator != null) {
						objAnimator.cancel();
						circularView.setProgress(0.0f);
					}
					if (animTimer != null) {
						animTimer.cancel();
					}
					received = false;
				} else if (received && data != 0 && data != 2 && data != 3) {
					received = false;
					if (data < 20000) { // 值太小重测
						msg = mHandler.obtainMessage();
						msg.what = BLE_DETECT_FAILED_VALUE_LOW;
						mHandler.sendMessage(msg);
						if (objAnimator != null) {
							objAnimator.cancel();
							circularView.setProgress(0.0f);
						}
						if (animTimer != null) {
							animTimer.cancel();
						}
					} else if (data >= 20000 && data < 60000) { // 数据值在{100,834}为正常值
						receivedWaterData = data / 1000;
					}
				}
			}
		}
	};
	
	
	/**
	 * 保存测试的值
	 */
	private void saveDetectValue() {
		DetectModel entity = new DetectModel();
		entity.setDetectType(Constants.DETECT_TYPE_WATER);
		entity.setDetectValue(receivedWaterData*0.1d);
		entity.setId(null);
		entity.setInsertTime(new Date());
		entity.setNurserType(tempNurserType);
		entity.setPartType(tempPartType);
		String userId = mSession.getUid();
		if(userId == null || "".equals(userId)) {
			userId = mSession.getMac();
		}
		entity.setUserId(userId);
		detectDao.insert(entity);
//		cursor.requery();
	}
	
	/**
	 * 保存到云端
	 */
	private void saveDetectResult() {
        boolean netUsable = NetWorkManager.getNewInstance().isNetworkConnected(mContext);
        //isAdded() 判断空指针
        if (netUsable && isAdded() && mContext != null) {
            mRequestQueue = Volley.newRequestQueue(mContext.getApplicationContext());
            // Request a string response from the provided URL.
            StringRequest stringRequest = new StringRequest(Request.Method.POST, Constants.URL_POST_DETECT_WATER_VALUE,
            		listener4success , new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
//                    Toast.makeText(mContext,"aaaaaaaaa",Toast.LENGTH_SHORT).show();
                }
            }){
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
					List<HashMap<String,String>> tempValueMapList = new ArrayList<HashMap<String,String>>();
					HashMap<String,String> tempValueMap = new HashMap<String,String>();
					String timestamp = SecurityUtil.getTimestamp();
					Map<String, String>  params = new HashMap<String, String>();
					params.put("device", "10");
					params.put("customerId",  mSession.getUid());
					params.put("companyId", Constants.COMPANY_ID);
					tempValueMap.put("top", "0");
					tempValueMap.put("productId", "-1");
					tempValueMap.put("avg", "0");
					tempValueMap.put("hardwareType", "1");
					if(tempNurserType == Constants.NURSER_TYPE_PRE){
						tempValueMap.put("beforeValue", nurserTypeValue);
					}else if(tempNurserType == Constants.NURSER_TYPE_POST){
						tempValueMap.put("afterValue", nurserTypeValue);
					}
					tempValueMap.put("type",partType);
                    tempValueMapList.add(tempValueMap);
                    if(tempValueMapList.size()>0) {
                    	params.put("detectionLists", new JSONArray(tempValueMapList).toString());
                    }
                    params.put(Constants.URL_TIMESTAMP,timestamp );
                    params.put(Constants.URL_KEY,SecurityUtil.getMd5String(timestamp));
                    return params;
                }
            };
            mRequestQueue.add(stringRequest);
            mRequestQueue.start();
        }else {
            Toast.makeText(mContext,R.string.net_connected_failure,Toast.LENGTH_SHORT).show();
        }
        return ;
    }
    
    
    Listener<String> listener4success = new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            String code = JsonUtil.getHeaderCode(response);
            if(!Constants.RESULT_JSON_HEADER_CODE_SUCCESS.equals(code)){
//                Toast.makeText(mContext, JsonUtil.getHeaderErrorInfo(response), Toast.LENGTH_SHORT).show();
            }
        }
    };

 
}
